typedef struct {

double dState;                          // Last position input
double iState;                          // Integrator state
double iMax, iMin;                      // Max and min allowable integrator state
double	pGain, iGain, dGain;            // proportional, integral, derivative gain

} SPid;

double UpdatePID(SPid * pid, double error, double temperature){

       double pTerm, dTerm, iTerm;
       pTerm = pid->pGain * error;      // calculate the proportional term
       pid->iState += error;            // calculate the integral state with appropriate limiting

       if (pid->iState > pid->iMax)
          pid->iState = pid->iMax;
       else if (pid->iState<pid->iMin)
               pid->iState = pid->iMin;

       iTerm = pid->iGain * pid->iState;    // calculate the integral term
       dTerm = pid->dGain * (temperature - pid->dState);
       pid->dState = temperature;
       return pTerm + iTerm - dTerm;
}







void main() {

}
